<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div id="root">
    <h2>今天天气很{{weatherInfo}}</h2>
    <button @click="changeWeather">切换天气</button>
</div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false;
    const vm = new Vue({
        el: '#root',
        data() {

            return {
                isHot: true,
                numbers: {
                    a: 1,
                    b: 2
                }
            }
        },
        methods: {
            changeWeather(e) {
                this.isHot = !this.isHot;
            }
        },
        computed: {
            weatherInfo: {
                get() {
                    return (this.isHot ? "炎热" : "凉爽");
                }
            }
        },
        /*watch: {
            // 正常写法
            /!*isHot: {
                // immediate: true, // 初始化时调用一下handler
                handler(valNew, valOld) {
                    console.log("isHot changed", valNew, valOld);
                }
            },*!/
            //简写（只适用于不需要immediate和deep的时候）
            'isHot'(valNew, valOld){
                console.log("isHot changed", valNew, valOld);
            }
        }*/
    });
    vm.$watch('isHot', function (valNew, valOld) {
        console.log("isHot changed", valNew, valOld);
    });
</script>
</html>